{{--继承模板--}}
@extends('admin.layouts.common')
@section('content')
    <style>
        .layui-code {
            border:1px solid #e6e6e6;
            border-left: 5px solid #4476A7;
            background-color: #FDFDFD;
        }
    </style>
    <div class="layui-row">
        <div style="background: #fff;padding: 10px 20px">
            @csrf
            <fieldset class="layui-elem-field">
                <legend>GatewayWorker 服务管理</legend>
                <div class="layui-field-box">
                    <i class="layui-icon start" style="color:#177ce3; display: none;font-size: 15px;">&#xe652; &nbsp;运行中 ......</i>
                    <i class="layui-icon reloads" style="color:#177ce3; display: none;font-size: 15px;">&#xe63d;&nbsp;重启中......</i>
                    <i class="layui-icon stop" style="color:#FF0000; display: none;font-size: 15px;">&#xe651;&nbsp;停止</i>
                    <i class="layui-icon status" style="color:#000000; display: none;font-size: 15px;">&#xe614; &nbsp;查看运行状态</i>
                    <i class="layui-icon layui-icon-close-fill close" style="position:relative;float:right;right:10px;top: 20px;z-index: 999;display: none;color:#4476A7;"></i>
                    <pre class="layui-code stream" style="font-size: 13px;display: none;"></pre>
                    <p>&nbsp;</p>
                    <div class="layui-btn-container">
                        <button class="layui-btn layui-btn-blue" lay-filter="start" lay-submit="">
                            <i class="layui-icon">&#xe652;</i>启动
                        </button>
                        <button class="layui-btn layui-btn-green  reload" lay-filter="reload" lay-submit="">
                            <i class="layui-icon">&#xe63d;</i>重启
                        </button>
                        <button class="layui-btn  layui-btn-red" lay-filter="stop" lay-submit="">
                            <i class="layui-icon">&#xe651;</i>停止
                        </button>
                        <button class="layui-btn  layui-btn-black" lay-filter="status" lay-submit="">
                            <i class="layui-icon">&#xe614;</i>状态
                        </button>
                    </div>
                </div>
            </fieldset>
        </div>
        <br>
        <div class="layui-card">
            <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title">
                    <li class="layui-this">后台设置</li>
                    <li>验证码</li>
                </ul>
                <div class="layui-tab-content" >
                    <div class="layui-tab-item layui-show"><br>
                        <div class="layui-anim layui-anim-up">
                            <form class="layui-form" lay-filter="form-system">
                                @csrf
                                <div class="layui-form-item">
                                    <label class="layui-form-label">分页数量</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="limit" lay-verify="limit" placeholder="请输入分页数量" class="layui-input">
                                        <div class="layui-form-mid layui-word-aux">
                                            <span style="color: red">*</span> 分页显示条数
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">系统名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="admin_name" placeholder="请输入系统名称" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">版权信息</label>
                                    <div class="layui-input-inline">
                                        <textarea name="admin_copyright" placeholder="请输入内容" class="layui-textarea"></textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button type="button" class="layui-btn layui-btn-blue" lay-submit="" lay-filter="sys">提交</button>
                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <div class="layui-tab-item"><br>
                        <div class="layui-anim layui-anim-up">
                            <form class="layui-form" lay-filter="form-system">
                                @csrf
                                <div class="layui-form-item">
                                    <label class="layui-form-label">管理员登录</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="code" value="open" title="开启">
                                        <input type="radio" name="code" value="close" title="关闭">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button type="button" class="layui-btn layui-btn-blue" lay-submit="" lay-filter="sys">提交</button>
                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="{{asset('layuiadmin/layui/layui.js')}}"></script>
    <script>
        layui.use(['util'], function(){
            var util = layui.util;
            //固定块
            util.fixbar({
                bar1: '&#xe669'
                ,css: {right: 25, bottom: 25}
                ,bgcolor: '#393D39'
                ,click: function(type){
                    if(type === 'bar1'){
                        window.location.reload();
                    }else{

                    }
                }
            });
        });
    </script>
    <script>
        layui.use(['form','layer','upload','element','code'], function(){
            var form = layui.form
                ,layer = layui.layer
                ,upload = layui.upload
                ,element = layui.element
                ,code = layui.code
                ,$ = layui.jquery;
            var _token =  $('meta[name="csrf-token"]').attr('content');
            //自定义验证规则
            var seytem = {!! $system !!};
            form.val("form-system", seytem);
            //监听提交
            form.on('submit(sys)', function(data){
                $.post("{{url('admin/config/edit')}}",data.field,function(res){
                    if(res.code == 1){
                        layer.msg(res.msg,function () {
                            window.location.reload();
                        });
                    }else if(res.code == 0){
                        layer.msg(res.msg);
                    }else{
                        layer.msg('你无操作权限！');
                    }
                },'json')
                return false;
            });

            //GatewayWorker 服务管理

            //启动
            form.on('submit(start)', function(){
               $.post("{{url('admin/gatewayworker/start')}}",{_token:_token});
              /* $.post("{{url('admin/gatewayworker/start')}}",{_token:_token},function(res){
                    if (res.code == 200) {
                        layer.msg('启动成功');
                        $('.stream').show();
                        $('.close').show();
                        $('.stream').text(res.msg);
                        $('.reloads').css('display','none');
                        $('.stop').css('display','none');
                        $('.status').css('display','none');
                        $('.start').css('display','block');
                        $('.reload').removeClass('layui-btn-disabled');
                        $('.reload').addClass('layui-btn-green');
                        $('.reload').attr("lay-filter","reload");
                    }else{
                        $('.stream').hide();
                        $('.close').hide();
                        layer.msg(res.msg);
                    }
                },'json')*/
                $.post("{{url('admin/gatewayworker/status')}}",{_token:_token},function(res){
                    if (res.code == 2001 || res.code == 200) {
                        layer.msg('查看状态成功');
                        $('.close').show();
                        $('.stream').show();
                        $('.stream').text(res.msg);
                        $('.reloads').css('display','none');
                        $('.stop').css('display','none');
                        $('.status').css('display','block');
                        $('.start').css('display','none');
                        $('.reload').removeClass('layui-btn-disabled');
                        $('.reload').addClass('layui-btn-green');
                        $('.reload').attr("lay-filter","reload");
                        $('.status').css('display','none');
                        if (res.code == 2001) {
                            $('.stop').css('display','block');
                            $('.reload').removeClass('layui-btn-green');
                            $('.reload').addClass('layui-btn-disabled');
                            $('.reload').attr("lay-filter","");
                        }else{
                            $('.start').css('display','block');
                        }
                    }else{
                        $('.stream').hide();
                        $('.close').hide();
                        layer.msg(res.msg);
                    }
                },'json')
                return false;
                alert(3);
            });

            //停止
            form.on('submit(stop)', function(){
                $.post("{{url('admin/gatewayworker/stop')}}",{_token:_token},function(res){
                    if (res.code == 2001) {
                        layer.msg('停止成功');
                        $('.stream').show();
                        $('.close').show();
                        $('.stream').text(res.msg);
                        $('.reloads').css('display','none');
                        $('.stop').css('display','block');
                        $('.status').css('display','none');
                        $('.start').css('display','none');
                        $('.reload').removeClass('layui-btn-green');
                        $('.reload').addClass('layui-btn-disabled');
                        $('.reload').attr("lay-filter","");
                    }else{
                        $('.stream').hide();
                        $('.close').hide();
                        layer.msg(res.msg);
                    }
                },'json')
                return false;
            });

            //重启
            form.on('submit(reload)', function(){
                $('.start').css('display','none');
                $('.stop').css('display','none');
                $('.status').css('display','none');
                $('.reloads').css('display','block');
                $.post("{{url('admin/gatewayworker/reload')}}",{_token:_token},function(res){
                    if (res.code == 2002) {
                        $('.stream').show();
                        $('.close').show();
                        $('.stream').text(res.msg);
                        layer.msg('重启成功');
                        $('.reloads').css('display','none');
                        $('.stop').css('display','none');
                        $('.status').css('display','none');
                        $('.start').css('display','block');
                        //$('.reload').addClass('layui-btn-green');
                    }else{
                        $('.stream').hide();
                        $('.close').hide();
                        layer.msg(res.msg);
                    }
                },'json')
                return false;
            });

            $('.close').click(function() {
                $('.stream').hide();
                $('.close').hide();
            })

            $(document).ready(function(){
                $.post("{{url('admin/gatewayworker/status')}}",{_token:_token},function(res){
                    if (res.code == 2001) {
                        $('.stop').css('display','block');
                        $('.reload').removeClass('layui-btn-green');
                        $('.reload').addClass('layui-btn-disabled');
                        $('.reload').attr("lay-filter","");
                    }else{
                        $('.start').css('display','block');
                    }
                });
            });


            //查看状态
            form.on('submit(status)', function(){
                $.post("{{url('admin/gatewayworker/status')}}",{_token:_token},function(res){
                    if (res.code == 2001 || res.code == 200) {
                        layer.msg('查看状态成功');
                        $('.close').show();
                        $('.stream').show();
                        $('.stream').text(res.msg);
                        $('.reloads').css('display','none');
                        $('.stop').css('display','none');
                        $('.status').css('display','block');
                        $('.start').css('display','none');
                        $('.reload').removeClass('layui-btn-disabled');
                        $('.reload').addClass('layui-btn-green');
                        $('.reload').attr("lay-filter","reload");
                        $('.status').css('display','none');
                        if (res.code == 2001) {
                            $('.stop').css('display','block');
                            $('.reload').removeClass('layui-btn-green');
                            $('.reload').addClass('layui-btn-disabled');
                            $('.reload').attr("lay-filter","");
                        }else{
                            $('.start').css('display','block');
                        }
                    }else{
                        $('.stream').hide();
                        $('.close').hide();
                        layer.msg(res.msg);
                    }
                },'json')
                return false;
            });

        });
    </script>
@endsection

